import api from '../assets/js/settings'

const hunru = {
    data() {
        return {
            course_id: 0,
            course_info: {
                teacher: {},
            },
        }
    },
    methods: {
        handleGOPay() {
            let token = this.$cookies.get('token')
            if (token) {
                this.$axios.post(api.pay, {
                    courses: [this.course_id],
                    total_amount: this.course_info.price,
                    subject: this.course_info.name,
                    pay_type: 1
                }, {
                    headers: {
                        'Authorization': 'Bearer ' + token
                    }
                }).then(res => {
                    if (res.data.code == 100) {
                        let pay_url = res.data.pay_url
                        open(pay_url, '_self')
                    }
                }).catch(() => {
                    this.$message({
                        message: "对不起，访问页面出错！请联系客服工作人员！"
                    });
                })
            } else {
                this.$message({
                    type: "error",
                    message: "请先登录"
                });
            }
        }
    }
}
export default hunru